"""加一"""


class Solution:
    def plusOne(self, digits):
        # 第一种方法，遍历加一判断，进位
        i = len(digits) - 1
        digits[i] += 1
        while i != -1:
            if digits[i] == 10 :
                digits[i] = 0
                if i != 0:
                    digits[i - 1] += 1
                else:
                    digits.insert(0,1)
            i -= 1
        print(digits)

        # 第二种，转整数后相加，在返回
        str1 = ""
        for i in digits:
            str1 += str(i)
        n = int(str1) + 1
        list = []
        for i in str(n):
            list.append(int(i))
        print(list)


if __name__ == '__main__':
    list1 = [9, 9]
    s = Solution()
    s.plusOne(list1)
